﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;
using System.Windows.Media;
using WcsZz.Extend;
using Color = System.Windows.Media.Color;
using ColorConverter = System.Windows.Media.ColorConverter;



namespace wms_wpf.Converter
{
  
    public class DuplicateReelIdToColorBrushConverter : IValueConverter
    {
       private readonly  Dictionary<string, int> _countMap = new Dictionary<string, int>();

        public DuplicateReelIdToColorBrushConverter() 
        {
            EventAggregatorHelper.EventAggregator.ResgiterMessage(async arg =>
            {

               _countMap.Clear();

            }, "ClearcountMap");
        }
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            var reelId = (string)value;
            if (!_countMap.ContainsKey(reelId))
            {
                _countMap.Add(reelId, 1);
                return new SolidColorBrush((Color)ColorConverter.ConvertFromString("Black")); // 或默认背景色
            }
            else
            {
                _countMap[reelId]++;
                return _countMap[reelId] > 1 ? new SolidColorBrush((Color)ColorConverter.ConvertFromString("orange")): 
                                               new SolidColorBrush((Color)ColorConverter.ConvertFromString("Black"));

            }
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}
